using System.Data;

namespace NetMigration.SqlAssemblers
{
    public class TSqlAssembler : ISqlAssembler
    {
        #region ISqlAssembler Members

        public string GetSqlToCreateTable(string tableName)
        {
            return string.Format("CREATE TABLE [{0}] (version int);", tableName);
        }

        public string GetSqlToCheckTableIsExist(string tableName)
        {
            return string.Format("SELECT object_id('{0}','U');", tableName);
        }

        public string GetSqlToSelect(string tableName)
        {
            return string.Format("SELECT * FROM [{0}];", tableName);
        }

        public string GetSqlToUpdateTable(string tableName, string columnName, int value)
        {
            return string.Format("UPDATE [{0}] SET [{1}]={2};", tableName, columnName, value);
        }

        public string GetSqlToInsertValue(string tableName, int value)
        {
            return string.Format("INSERT INTO [{0}] VALUES({1});", tableName, value);
        }

        public string GetSqlToAddColumn(string tableName, string columnName, DbType columnType)
        {
            var type = string.Empty;
            if (columnType == DbType.String)
            {
                type = "ntext";
            }
            return string.Format("ALTER TABLE [{0}] ADD [{1}] {2} NULL;", tableName, columnName, type);
        }

        public string GetSqlToDropTable(string tableName)
        {
            return string.Format("IF object_id('{0}','U') IS NOT NULL DROP TABLE [{0}];", tableName);
        }

        #endregion
    }
}